home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.04 Apr 87 / help demo.c / atoi.c next >
Encoding:
C/C++ Source or Header  |  1987-02-02  |  811 b   |  38 lines  |  [TEXT/KAHL]

  1. /***********************************************************************
  2.  * atoi.c - much smaller than unix & stdio libraries 
  3.  *
  4.  * WN Rausch
  5.  * January 1987
  6.  **********************************************************************/
  7.  
  8. #include <MacTypes.h>
  9. #include <pascal.h>
  10. #include <strings.h>
  11.  
  12. #define isspace(c) (c == ' ' || c == '\t')
  13. #define ZERO 48
  14.  
  15. /**********************************************************************/
  16. atoi(string)
  17. register char *string;   /* must be NULL terminated */
  18.   {
  19.   register long answer = 0L;
  20.   Boolean negative = FALSE;
  21.   
  22.   while (isspace(*string))
  23.       string++;
  24.       
  25.   if (*string == '-')
  26.       negative = TRUE;
  27.       
  28.   while (*string)
  29.       {
  30.       answer = (answer * 10) + (*string - ZERO);
  31.       string++;
  32.       }
  33.       
  34.   if (negative)
  35.       answer = 0 - answer;
  36.   
  37.   return (int)answer;
  38.   }